import cache from '@/plugins/cache'
export const recordBack = (proxy: any, formData: any) => {
  const path = proxy.$route.fullPath
  const recordArr = cache.session.getJSON(path)
  if (!recordArr || recordArr.length == 0) return
  if (recordArr.length == 1) {
    if (recordArr[0].type == 'form') {
      formData[recordArr[0].key] = ''
      cache.session.setJSON(path, [])
    }
  } else {
    if (recordArr[0].type == 'form') {
      const key = recordArr[0].key
      recordArr.shift()
      const filterArr = recordArr.filter((v: any) => v.key == key)
      if (filterArr.length == 0) {
        formData[key] = null
      } else {
        formData[key] = filterArr[0].value
      }
      cache.session.setJSON(path, recordArr)
    }
  }
}
export const initRecord = (proxy: any) => {
  const path = proxy.$route.fullPath
  cache.session.remove(path)
}
